package com.c.result;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class ListResult<T> extends BaseResult<T> {

	private static final long serialVersionUID = 5630518079179620343L;

	/** Amount of all items with condition, not only in the list */
	private long total;
	/** List of items */
	private List<T> data;
	private List<T> rows;

	/**
	 * Query result in list
	 */
	public ListResult() {
		super(false, "");
		data = new ArrayList<T>();
	}

	/**
	 * 不分页构造函数
	 * 
	 * @param data
	 */
	public ListResult(List<T> data) {
		super(true, "");
		this.data = data;
	}

	/**
	 * 带分页构造函数
	 * 
	 * @param data
	 */
	public ListResult(long total, List<T> data) {
		super(true, "");
		this.total = total;
		this.data = data;
	}

	/**
	 * Get query result
	 * 
	 * @return Query items
	 */
	public List<T> getData() {
		return data;
	}

	/**
	 * Set query result
	 * 
	 * @param data
	 *            - Query items
	 */
	public void setData(List<T> data) {
		this.data = data;
	}

	/**
	 * Set query result
	 * 
	 * @param data
	 *            - Query items
	 */
	public void setData(Set<T> dataSet) {
		if (dataSet != null) {
			this.data = new ArrayList<T>();
			for (T _t : dataSet) {
				this.data.add(_t);
			}
		}
	}

	/**
	 * Set query result
	 * 
	 * @param data
	 *            - Query items
	 */
	public void setRows(Set<T> rowSet) {
		if (rowSet != null) {
			this.rows = new ArrayList<T>();
			for (T _t : rowSet) {
				this.rows.add(_t);
			}
		}
	}

	/**
	 * Get query result
	 * 
	 * @return Query items
	 */
	public List<T> getRows() {
		return rows;
	}

	/**
	 * Set query result
	 * 
	 * @param data
	 *            - Query items
	 */
	public void setRows(List<T> rows) {
		if (rows != null) {
			this.rows = rows;
		}
	}

	/**
	 * Get amount of all items with condition
	 * 
	 * @return Amount of all items
	 */
	public long getTotal() {
		return total;
	}

	/**
	 * Set amount of all items with condition
	 * 
	 * @param total
	 *            - Amount of all items
	 */
	public void setTotal(long total) {
		this.total = total;
	}

	public ListResult<T> appendJsonIncludes(String... propNames) {
		for (String propName : propNames) {
			get_jsonSer().include(propName);
		}
		return this;
	}

	public ListResult<T> appendJsonExcludes(String... propNames) {
		for (String propName : propNames) {
			get_jsonSer().exclude(propName);
		}
		return this;
	}
}
